/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conexao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Conexao {
    public static Connection getConexao() throws Exception {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            return DriverManager.getConnection("jdbc:mysql://localhost:3306/sgp", "root", "n1o3t7e9");
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }

    public static void closeConexao(Connection conexao, PreparedStatement stmt, ResultSet rs) throws Exception {
        close(conexao, stmt, rs);
    }

    public static void closeConexao(Connection conexao, PreparedStatement stmt) throws Exception {
        close(conexao, stmt, null);
    }

    public static void closeConexao(Connection conexao) throws Exception {
        close(conexao, null, null);
    }

    private static void close(Connection conexao, PreparedStatement stmt, ResultSet rs) throws Exception {
        try {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
            if (conexao != null) {
                conexao.close();
            }
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }    
}
